#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

using namespace std;
void show_sigset(sigset_t *pending) {
    for (int i = 1; i < 32; ++i) {
        if (sigismember(pending, i)) {
            cout << "1";
        } else {
            cout << "0";
        }
    }
    cout << endl;
}



int main() {

    sigset_t in; 
    sigset_t out;
    sigemptyset(&in);
    sigemptyset(&out);
    sigaddset(&in, 2);
    sigset_t pend;
    sigemptyset(&pend);
    int count = 0;
    sigprocmask(SIG_SETMASK, &in, &out);
    while (true) {
        sigpending(&pend);
        show_sigset(&pend);
        sleep(1);
        if (count > 20) {
            cout << "解除阻塞" << endl;
            sigprocmask(SIG_SETMASK, &out, &in);
            cout << "in: "; 
            show_sigset(&in);
            cout << "out: ";
            show_sigset(&out);
        }
        count++;
    }


    //if (argc != 3) {
    //    cerr << "Usage:" << argv[0] << " signum pid " << endl;
    //} else {
    //    kill(atoi(argv[2]), atoi(argv[1]));
    //}
    return 0; 
}
